package kr.hkit.powerjava.chapter21.work;

import java.util.Scanner;

class MyException extends Exception {

	public MyException() {
		super("사용자 정의 예외");

	}

}

class search {
	private int a;
	private int b;
	Scanner sc = new Scanner(System.in);

	void searchArray(int[] Sarr) throws MyException {
		System.out.println("배열에서 찾는 값을 입력하시오.");
		a = sc.nextInt();
		int c = 0;
		
		for (int i = 0; i < Sarr.length; i++) {
			b = Sarr[i];
			if (a == b) {
				c=b;
				break;			
			} 
		}
		
		if(a==c){
			System.out.println( "배열에 값이 있습니다.");
		}else
		
		throw new MyException();
	}
}

public class programming3 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] arr = { 1, 2, 3, 4, 5, 6 };

		search a = new search();
		try {
			a.searchArray(arr);
		} catch (MyException e) {
			System.out.println(e.getMessage());
			e.printStackTrace();
		}
	}
}
